package com.haiwen.com;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 实现servlet的步骤：
 * 1.创建一个web工程 创建包 创建类
 * 2.继承HttpServlet
 * 3.重写HttpServlet的service方法
 * 4.接受请求 响应结果
 * 5.配置访问路径
 */

@WebServlet("/ser01")
/*
@WebServlet(name = "servlet01",urlPatterns = "/s01")
@WebServlet(name = "servlet01",urlPatterns = {"/s01","s02"})
@WebServlet(name = "servlet01",value = "/s01")
@WebServlet(name = "servlet01",value = {"/s01","/s02"})
*/
public class Sercler01 extends HttpServlet {
    /**
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        //1.接收请求
        String username = req.getParameter("username");
        System.out.println("请求参数" + username);
        //2.响应结果
        resp.getWriter().write("hello " + username);
    }
}
